package com.chris.homecare.screens
{
	import com.chris.homecare.components.BreadcrumbComponenet;
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.components.renderers.EmployeesListHeaderRenderer;
	import com.chris.homecare.components.renderers.EmployeesListRenderer;
	import com.chris.homecare.data.DataUtil;
	import com.chris.homecare.data.Employee;
	import com.chris.homecare.utils.CommonUtils;
	import com.chris.homecare.utils.ScreenNames;
	
	import feathers.controls.GroupedList;
	import feathers.controls.Screen;
	import feathers.controls.renderers.IGroupedListHeaderOrFooterRenderer;
	import feathers.controls.renderers.IGroupedListItemRenderer;
	import feathers.controls.text.TextFieldTextRenderer;
	import feathers.core.ITextRenderer;
	import feathers.layout.VerticalLayout;
	import feathers.skins.StandardIcons;
	
	import starling.display.Quad;
	import starling.events.Event;
	import starling.textures.Texture;
	
	[Event(name="employeeData",type="starling.events.Event")]

	public class TeamScreen extends Screen
	{
		public static const EMPLOYEE_DATA:String = "employeeData"
		
		private var list:GroupedList;

		private var backQuad:Quad;
		private var header:HeaderComponent;
		private var breadcrumbComp:BreadcrumbComponenet;
		public function TeamScreen()
		{
			super();
		}
		
		override protected function initialize():void
		{
			CommonUtils.previousScreen = ScreenNames.MENU_SCREEN;
			
			var layout:VerticalLayout = new VerticalLayout();
			this.layout = layout;
			
			header = new HeaderComponent();
			header.addEventListener(Event.COMPLETE, onMenuBtnTrigger);
			addChild(header);
			
			breadcrumbComp = new BreadcrumbComponenet("Info", "Team");
			addChild(breadcrumbComp);
			
			list = new GroupedList();
			list.dataProvider = DataUtil.getAllEmployees();
			list.headerRendererFactory = function():IGroupedListHeaderOrFooterRenderer
			{
				var renderer:EmployeesListHeaderRenderer = new EmployeesListHeaderRenderer();
				return renderer;
			};
			
			list.itemRendererFactory = function():IGroupedListItemRenderer
			{
				var renderer:EmployeesListRenderer = new EmployeesListRenderer();
				return renderer;
			};			
			
			list.addEventListener(Event.CHANGE, list_changeHandler);
			this.addChild(list);
			list.backgroundSkin = new Quad(10,10,0xFFFFFF);
			list.backgroundDisabledSkin = new Quad(10,10,0xFFFFFF);
			super.initialize();
		}
		
		private function onMenuBtnTrigger(event:Event):void
		{
			this.dispatchEventWith(Event.COMPLETE, false, {page: "Menu"});
		}
		
		private function labelRenderer():ITextRenderer
		{
			var textRenderer:TextFieldTextRenderer = new TextFieldTextRenderer();
			textRenderer.isHTML = true;
			return textRenderer;
		}
		
		private function accessorySourceFunction(item:Object):Texture
		{
			return StandardIcons.listDrillDownAccessoryTexture;
		}
		
		
		override protected function draw():void
		{
			list.width = stage.stageWidth;
			list.height = stage.stageHeight - list.y;
			super.draw();
		}
		
		private function list_changeHandler(event:Event):void
		{
			this.dispatchEventWith(EMPLOYEE_DATA, false, Employee(list.selectedItem));
		}
		
	}
}